import {messages} from "share/common";
import React from 'react'
import {connect} from 'react-redux'
import { Tabs, Affix, Button } from 'antd';
import Condition from "components/condition";
import WriteOff from "containers/finance-setting/set-of-books/write-off";
import FinancialAccount from "containers/finance-setting/set-of-books/financial-account";
import menuRoute from "routes/menuRoute";
const If = Condition.If;
const TabPane = Tabs.TabPane;

class setOfBookSetting extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      status: 'write-off'
    }
  }

  componentWillMount() {
  }

  handleChangeStatus = key => {
    this.setState({status: key})
  };

  goBack = () => {
    this.context.router.push(menuRoute.getRouteItem('set-of-books').url);
  };

  render(){
    const { status } = this.state;
    const { setOfBooks } = this.props;
    const style = {
      width: 'calc(100% - 202px)',
      height: '50px',
      lineHeight: '50px',
      position: 'fixed',
      bottom: '0',
      zIndex: '5',
      marginLeft: '-35px',
      background: '#fff',
      borderTop: '1px solid rgba(0, 0, 0, 0.067)',
      boxShadow: '0px -5px 5px rgba(0, 0, 0, 0.067)',
      paddingLeft: '20px'
    };
    return(
      <div>
        <h2>{setOfBooks.setOfBooksName}</h2>
        <Tabs defaultAcitiveKey={status} onChange={this.handleChangeStatus}>
          <TabPane key={'write-off'} tab={messages('finance-setting.key157')/*核销规则*/}/>
          {/*<TabPane key={'financial-account'} tab={'核算设置'}/>*/}
        </Tabs>
        <If value={status === 'write-off'}>
          <WriteOff setOfBooks={setOfBooks}/>
        </If>
        {/*<If value={status === 'financial-account'}>*/}
          {/*<FinancialAccount setOfBooks={setOfBooks}/>*/}
        {/*</If>*/}
        <Affix offsetBottom={0} style={style}>
          <Button onClick={this.goBack}>{messages('common.back')/*返回*/}</Button>
        </Affix>
      </div>
    )
  }
}

setOfBookSetting.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state){
  return {
    setOfBooks: state.cache.setOfBooks
  }
}

export default connect(mapStateToProps)(setOfBookSetting);
